﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Collections.Generic;

public partial class BaseData_ServiceStationsMain : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("200600109");
        if (!IsPostBack)
        {
            AspNetPager1.PageSize = Convert.ToInt32(ConfigurationManager.AppSettings["RowCountPerPage"].ToString());
            SearchControl1.InitParam("ServiceSites", "SS_ID", "SS_Name", "ServiceSitesListControl1", "rptServiceSites", "AspNetPager1");
            Bind();
        }
    }

    private void Bind()
    {
        try
        {

            int recordCount;
            DataSet dst = new BLL.ServiceSites().GetMain(GetStartIndex(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize), AspNetPager1.PageSize, "", out recordCount);
            ServiceSitesListControl1.Bind(dst);
            AspNetPager1.RecordCount = recordCount;
        }
        catch (Exception ex)
        {
            Share.Alert(this.Page, ex.Message);
        }
    }
    
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        int pageCount, rowCount;
        if (SearchControl1.IsSearchResult)
        {
            Repeater rpt = (Repeater)ServiceSitesListControl1.FindControl("rptServiceSites");
            if (rpt != null)
            {
                string strSql;
                SearchControl1.BindParentPageControl(rpt, AspNetPager1, SearchControl1.DataTableName, SearchControl1.PrimaryKeyColumnName, SearchControl1.StrCondition, AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, out pageCount, out rowCount, out strSql);
            }
        }
        else
        {
            DataSet dst = new BLL.ServiceSites().GetMain(GetStartIndex(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize), AspNetPager1.PageSize, "", out rowCount);
            ServiceSitesListControl1.Bind(dst);
        }
    }

    private int GetStartIndex(int pageIndex, int pageSize)
    {
        return 1 + (pageIndex - 1) * pageSize;
    }

    public void Add()
    {
        if (Check.CheckPermission("200600109", "00001"))
        {
            Response.Redirect("AddServiceStation.aspx");
        }
        else
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
    }

    public void Update()
    {
        if (Check.CheckPermission("200600109", "00002"))
        {
            List<int> s = ServiceSitesListControl1.Selected;
            if (s.Count > 0)
            {
                Response.Redirect("ServiceStationDetail.aspx?code=" + s[0]);
            }
            else
            {
                Page.RegisterStartupScript("StartUp", "<script language=javascript>alert('请选择一条需要编辑的记录')</script>");
            }
        }
        else
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
    }

    public void Delete()
    {
        if (Check.CheckPermission("200600109", "00003"))
        {
            List<int> s = ServiceSitesListControl1.Selected;
            new BLL.ServiceSites().Delete(s);
            Share.InsertLog("200600109", "00003");
            Response.Redirect("ServiceStationsMain.aspx");
        }
        else
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
    }
}
